Subscribe Us

Responsive Advertisement

Advertisement

URI Online Judge | 1441 Hailstone Sequences solution in cpp

 

uri 1441 solution in cpp

by ujjal roy


#include<bits/stdc++.h>

using namespace std;

main()

{

    int h;

    while(cin>>h)

    {


        if(h==0) break;

         int max=h;

        while(h!=1)

        {


        if(h%2==0) h=h/2;

        else h=3*h+1;

        if(h>max) max=h;

        }


        cout<<max<<endl;


    }

    return 0;

}


Post a Comment

0 Comments